package com.hk.commons.utils;

import com.hk.commons.UserProductConstant;
import com.hk.commons.vo.ProductUserRiskLevelResponse;
import org.apache.commons.lang3.StringUtils;

/**
 * 功能描述
 * @author luocheng
 * 创建时间2017/9/29.
 */
public class MatchRuleUtil {

    /**
     * 购买产品匹配用户等级是否一样
     * @param userRiskLevel 用户风险等级
     * @param proRiskLevel 产品风险等级
     * @return
     */
    public static ProductUserRiskLevelResponse getMatchRule(String userRiskLevel, String proRiskLevel) {
        ProductUserRiskLevelResponse productUserRiskLevelResponse = new ProductUserRiskLevelResponse();

        if(StringUtils.isBlank(userRiskLevel)) {
            productUserRiskLevelResponse.setRiskMatch(false);
            productUserRiskLevelResponse.setIsRiskNoMathText(SaleMatchRuleEnum.X_BUY.getValue());
            return productUserRiskLevelResponse;
        }

        if(userRiskLevel.equals(UserProductConstant.USER_RISK_LEVEL_C1_1)) {
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_2) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_3) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_4) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_5)) {
                productUserRiskLevelResponse.setRiskMatch(false);
                productUserRiskLevelResponse.setIsRiskNoMathText(SaleMatchRuleEnum.X_BUY.getValue());
                return productUserRiskLevelResponse;
            }
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_1)) {
                productUserRiskLevelResponse.setRiskMatch(true);
                productUserRiskLevelResponse.setIsRiskMatchText(SaleMatchRuleEnum.MATCH_BUY.getValue());
                return productUserRiskLevelResponse;
            }
        }

        if(userRiskLevel.equals(UserProductConstant.USER_RISK_LEVEL_C1)) {
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_2) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_3) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_4)) {
                productUserRiskLevelResponse.setRiskConfirmAgain(true);
                productUserRiskLevelResponse.setIsRiskConfirmAgainText(SaleMatchRuleEnum.IS_RISK_CONFIRM_AGAIN.getValue());
                return productUserRiskLevelResponse;
            }
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_1)) {
                productUserRiskLevelResponse.setRiskMatch(true);
                productUserRiskLevelResponse.setIsRiskMatchText(SaleMatchRuleEnum.MATCH_BUY.getValue());
                return productUserRiskLevelResponse;
            }
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_5)) {
                getA1A2(productUserRiskLevelResponse);
                return productUserRiskLevelResponse;
            }
        }

        if(userRiskLevel.equals(UserProductConstant.USER_RISK_LEVEL_C2)) {
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_3) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_4)) {
                productUserRiskLevelResponse.setRiskConfirmAgain(true);
                productUserRiskLevelResponse.setIsRiskConfirmAgainText(SaleMatchRuleEnum.IS_RISK_CONFIRM_AGAIN.getValue());
                return productUserRiskLevelResponse;
            }
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_1) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_2)) {
                productUserRiskLevelResponse.setRiskMatch(true);
                productUserRiskLevelResponse.setIsRiskMatchText(SaleMatchRuleEnum.MATCH_BUY.getValue());
                return productUserRiskLevelResponse;
            }
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_5)) {
                 getA1A2(productUserRiskLevelResponse);
                return productUserRiskLevelResponse;
            }
        }

        if(userRiskLevel.equals(UserProductConstant.USER_RISK_LEVEL_C3)) {
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_4)) {
                productUserRiskLevelResponse.setRiskConfirmAgain(true);
                productUserRiskLevelResponse.setIsRiskConfirmAgainText(SaleMatchRuleEnum.IS_RISK_CONFIRM_AGAIN.getValue());
                return productUserRiskLevelResponse;
            }
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_1) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_2) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_3)) {
                productUserRiskLevelResponse.setRiskMatch(true);
                productUserRiskLevelResponse.setIsRiskMatchText(SaleMatchRuleEnum.MATCH_BUY.getValue());
                return productUserRiskLevelResponse;
            }
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_5)) {
                getA1A2(productUserRiskLevelResponse);
                return productUserRiskLevelResponse;
            }
        }

        if(userRiskLevel.equals(UserProductConstant.USER_RISK_LEVEL_C4)) {
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_1) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_2) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_3) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_4)) {
                productUserRiskLevelResponse.setRiskMatch(true);
                productUserRiskLevelResponse.setIsRiskMatchText(SaleMatchRuleEnum.MATCH_BUY.getValue());
                return productUserRiskLevelResponse;
            }
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_5)) {
                getA1A2(productUserRiskLevelResponse);
                return productUserRiskLevelResponse;
            }
        }

        if(userRiskLevel.equals(UserProductConstant.USER_RISK_LEVEL_C5)) {
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_1) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_2) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_3) || proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_4)) {
                productUserRiskLevelResponse.setRiskMatch(true);
                productUserRiskLevelResponse.setIsRiskMatchText(SaleMatchRuleEnum.MATCH_BUY.getValue());
                return productUserRiskLevelResponse;
            }
            if(proRiskLevel.equals(UserProductConstant.PRODUCT_RISK_LEVEL_5)) {
                productUserRiskLevelResponse.setRiskConfirmHigh(true);
                productUserRiskLevelResponse.setIsRiskConfirmHighText(SaleMatchRuleEnum.IS_RISK_CONFIRM_HIGH.getValue());
                return productUserRiskLevelResponse;
            }
        }

        return productUserRiskLevelResponse;
    }

    private static void getA1A2(ProductUserRiskLevelResponse productUserRiskLevelResponse) {
        productUserRiskLevelResponse.setRiskConfirmHighAgain(true);
        productUserRiskLevelResponse.setIsRiskConfirmHighAgainText(SaleMatchRuleEnum.IS_RISK_CONFIRM_HIGH_AGAIN.getValue());
    }

}
